#include "Server.hpp"
#include "Router.hpp"
#include "ThreadPool.hpp"
#include <functional>

using task_t = std::function<void()>;
using namespace ThreadPoolModule;

int main(int argc, char *args[])
{
    if (argc != 2)
    {
        std::cerr << "Usage: Server + port" << std::endl;
        exit(errno);
    }

    Router router;

    in_port_t port = std::stoi(args[1]);
    UDPServer server(port, [&router](const std::string &message, const InetAddr &client, int fd)
                     {
        task_t func = std::bind(&Router::RouteMessage, &router, message, client, fd);
        ThreadPool<task_t>::GetInstance()->PushTask(func); });
    server.Start();
    return 0;
}

